home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 1 / PC Actual CD 01.iso / share / dos / demos / planets / source.lzh / XIONCODE.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-04-28  |  3.1 KB  |  146 lines

  1.  
  2. ;
  3. ;   XIONCODE.ASM
  4. ;
  5. ;   (Simon Hern, 1994)
  6. ;
  7. ;   Assembler routine to dent part of a planet surface
  8. ;
  9. ;   The Skin array is rolled and squashed to make a sphere
  10. ;   The sphere is then sliced in half and all of the top half is lifted
  11. ;   Riff data is used to line up the slices
  12. ;
  13. ;   Called from MAKEXION.C
  14. ;   '_skin' is an array of integers (RHO by 2*RHO) filling exactly one
  15. ;       segment of memory (64k)
  16. ;   '_riff' is the riff data - an array of bytes RHO/2 by RHO/2
  17. ;
  18.  
  19.  
  20.  
  21.     public _fracture    ; Exported routine
  22.  
  23.  
  24. RHO     EQU 128     ; Surface resolution (same as in PLANET.H)
  25.  
  26.  
  27. _Text   SEGMENT BYTE PUBLIC 'Code'
  28.  
  29.  
  30. ; (void) Fracture( (int)rf_num, (int)blast, (int)x_start )
  31. ;   rf_num : the riff to use (RHO/2 to choose from); angles the slice
  32. ;   blast : the amount by which to displace the fractured surface
  33. ;   x_start : starting position in terms of longitude (0 to 2*RHO-1)
  34.  
  35. _fracture:
  36.     push bp
  37.     mov bp,sp
  38.     push si
  39.     push di
  40.     push ds
  41.     push es
  42.     mov dx,w[bp+6]              ; blast
  43.     mov ah,b[bp+4]              ; rf_num
  44.     mov cl,b[bp+8]              ; x_start
  45.     xor ch,ch
  46.  
  47.     push ds
  48.     pop es
  49.     xor al,al
  50.     shr ax,1
  51.     shr ax,1                    ; (ax = 64 * rf_num, where 64=RHO/2)
  52.     add ax,OFFSET _riff
  53.     mov bp,ax                   ; es:bp -> riff[rf_num][0]
  54.  
  55.     push bp
  56.     push cx
  57.  
  58.     push SEG _skin
  59.     pop ds
  60.     mov di,cx
  61.     shl di,1                    ; ds:di -> skin[0][x_start]
  62.     dec cl
  63.     mov si,cx
  64.     shl si,1                    ; ds:si -> skin[0][(x_start-1) % (2*RHO)]
  65.  
  66.     xor bl,bl
  67.     mov cl,64
  68. f01:
  69.     mov bh,es:b[bp]             ; fill in two quadrants of skin
  70.     inc bp                      ;  si,di point to start of columns
  71.     cmp bh,0                    ;  bx gives offset down column
  72.     jz f05                      ;  cl counts
  73.     dec bh
  74.     jz f06
  75.     shl bx,1
  76. f02:
  77.     add w[di+bx],dx
  78.     add w[si+bx],dx
  79.     dec bh
  80.     dec bh
  81.     jnz f02
  82. f06:
  83.     add w[di],dx
  84.     add w[si],dx
  85.  
  86. f05:
  87.     inc di                      ; next columns
  88.     inc di                      ; di,si stay in range 0 to (2*RHO-1)
  89.     and di,511                  ;  times 2 since we're using words not bytes
  90.     dec si
  91.     dec si
  92.     and si,511
  93.     dec cl
  94.     jnz f01
  95.  
  96.     pop cx
  97.     pop bp
  98.  
  99.     add cl,128
  100.     mov di,cx
  101.     shl di,1                    ; ds:di -> skin[0][(x_start+RHO) % (2*RHO)]
  102.     dec cl
  103.     mov si,cx
  104.     shl si,1                    ; ds:si -> skin[0][(x_start+RHO-1) % (2*RHO)]
  105.  
  106.     xor bl,bl
  107.     mov cl,64
  108. f03:
  109.     mov bh,127                  ; now do the other two quadrants
  110.     sub bh,es:b[bp]
  111.     inc bp
  112.     cmp bh,0
  113.     jz f07
  114.     dec bh
  115.     jz f08
  116.     shl bx,1
  117. f04:
  118.     add w[di+bx],dx
  119.     add w[si+bx],dx
  120.     dec bh
  121.     dec bh
  122.     jnz f04
  123. f08:
  124.     add w[di],dx
  125.     add w[si],dx
  126.  
  127. f07:
  128.     inc di                      ; next columns
  129.     inc di
  130.     and di,511
  131.     dec si
  132.     dec si
  133.     and si,511
  134.     dec cl
  135.     jnz f03
  136.  
  137.     pop es
  138.     pop ds
  139.     pop di
  140.     pop si
  141.     pop bp
  142.     ret
  143.  
  144. _Text ENDS
  145.  
  146.